package com.study.SpringBootLesson4.filter;

import org.springframework.web.filter.OncePerRequestFilter;

import javax.servlet.FilterChain;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebFilter;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author 赵超
 * @Description springboot 注解注册filter学习
 * @create 2017-11-29 10:59
 **/
@WebFilter(servletNames = "myServlet")
//@WebFilter(urlPatterns = "/myServer")
public class MyFilter extends OncePerRequestFilter {
    @Override
    protected void doFilterInternal(HttpServletRequest httpServletRequest,
                                    HttpServletResponse httpServletResponse, FilterChain filterChain)
            throws ServletException, IOException {

        ServletContext servletContext = httpServletRequest.getServletContext();

        servletContext.log("myFilter");

        filterChain.doFilter(httpServletRequest, httpServletResponse);
    }
}
